package org.linphone.http;

import android.app.Application;
import android.content.Context;
import android.util.Log;

import com.yanzhenjie.andserver.annotation.Controller;
import com.yanzhenjie.andserver.annotation.GetMapping;
import com.yanzhenjie.andserver.annotation.PostMapping;
import com.yanzhenjie.andserver.annotation.RequestParam;
import com.yanzhenjie.andserver.annotation.ResponseBody;

import org.linphone.app.MyApplication;
import org.linphone.utils.SpUtil;

@Controller
public class SipConfig {
        Context ctx = MyApplication.getContext();

    @GetMapping("/sipLogin") //不要带html
    public String sipConfigweb(){ //写完了需要build一下,自动生成拦截代码;
        return "forward:/login.html";
    }
    /**
     * SIP账户配置
     */
    @ResponseBody
    @PostMapping("/changeSip")
    public String sipConfigurationFun(Context context
            , @RequestParam("username") String userName
            , @RequestParam("password") String password
            , @RequestParam("domain") String domain
            , @RequestParam("serverip") String serverIP
            , @RequestParam("serverport") String serverPort) {


        if (!"".equals(userName) && !"".equals(password) && !"".equals(domain) &&
                !"".equals(serverIP)) {//判断有问题:没有检测域名
            SpUtil.putString(ctx,"userName",userName);
            SpUtil.putString(ctx,"password",password);
            SpUtil.putString(ctx,"domain",domain);
            SpUtil.putString(ctx,"serverIP",serverIP);
            SpUtil.putString(ctx,"serverPort",serverPort);
            return  "提交成功" + "ConfigurationController获取到了配置信息:" + userName
                    +password +domain + serverIP ;

            } else {
            return  "必填项不能为空";
        }
    }
}


